package cn.itsource.service.driverSummaryFeign;

import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.domain.DriverSummaryInfo;
import cn.itsource.mapper.DriverSummaryMapper;
import cn.itsource.openfeign.DriverSummaryOpenFeign;
import cn.itsource.pojo.domain.DriverSummary;
import cn.itsource.result.JSONResult;
import cn.itsource.utils.RConst;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @program fccar_tt
 * @Description
 * @Author TT
 * @Date 2024/09/24 19:35
 * @Version 1.0
 */
@RestController
public class DriverSummaryOpenfeignImpl implements DriverSummaryOpenFeign {
    @Autowired
    private DriverSummaryMapper driverSummaryMapper;

    @Override
    public JSONResult updateDriverSummery(Long diverId) {
        DriverSummary driverSummary = driverSummaryMapper.selectOne(new LambdaQueryWrapper<DriverSummary>()
                .eq(DriverSummary::getId, diverId));
        if (driverSummary!=null){
            //修改总订单数
            driverSummary.setTotalOrders(driverSummary.getTotalOrders()+RConst.Num.INT_1);
            //修改当日取消订单数
            driverSummary.setTodayCancel(driverSummary.getTodayCancel()+ RConst.Num.INT_1);
            //修改总取消订单数
            driverSummary.setTotalCancel(driverSummary.getTotalCancel()+RConst.Num.INT_1);
            //修改时间
            driverSummary.setUpdateTime(new Date());
            driverSummaryMapper.updateById(driverSummary);
            return JSONResult.success();
        }
        return JSONResult.error("订单取消失败");
    }

    @Override
    public JSONResult getDriverSummaryInfo() {
        //获取到司机的结算对象
        DriverSummary driverSummary = driverSummaryMapper.selectById(StpUtil.getLoginIdAsLong());
        return JSONResult.success(new DriverSummaryInfo(driverSummary.getTodayComplaint(),
                driverSummary.getTodayCancel()));
    }
}
